var ques = {
    userInfo: null,
    URL: {
        saveQuesUrl: "/api/questionnaire/saveQues",
    },
    detail: {
        checkLogin: function () {
            $.post(login.URL.checkLoginUrl, {}, function (data) {
                if (!data.hasError) {
                    ques.userInfo = data.object;
                    if (ques.userInfo.quesStatus == 1) {
                        window.location.href = "index.html";
                    }
                    $.pop.load(false, null);
                } else {
                    window.location.href = data.errUrl;
                }
            }, "json").error(function (XMLHttpRequest, textStatus, errorThrown) {
                $.pop.load(false, null);
                $.pop.tips("系统繁忙，请稍后" + XMLHttpRequest.status + "," + XMLHttpRequest.readyState + "," + textStatus);
            });
        },
        saveQues: function () {
            var quesJson = new Array();
            var dls = $(".questionnaire").find("dl");
            var answers = new Array();
            var actId = $("#actId").val();
            $.each(dls, function (index, val) {
                var ques = $(this).find("dt").first().html();
                var quesId = $(this).find("dt").first().attr("data-id");
                var answer = "";
                if (index == 0) {
                    var q1 = $("input[name='q1']:checked").val();
                    if (!__JsUtil.isNullOrEmpty(q1)) {
                        answer = q1;
                        answers.push(answer);
                    }
                } else {
                    answer = $(this).find(".cur").length;
                    if (answer > 0) {
                        answers.push(answer);
                    }
                }
                //console.info("actId=" + actId + "!question=" + ques + "!answer=" + answer);
                quesJson.push({"actId": actId, "quesNo": quesId,"question": ques, "answer": answer});
            });
            // console.info(quesJson);
            // if (answers.length < 20) {
            //     $.pop.tips("请先完成问卷");
            //     return false;
            // }
            var opts={
                left:{
                    text:"确认",
                    call:function(){
                        $.pop.load(true, "正在提交...");
                        $.post(ques.URL.saveQuesUrl, {quesJsonStr: JSON.stringify(quesJson)}, function (data) {
                            $.pop.load(false, null);
                            if (!data.hasError) {
                                window.location.href = "index.html";
                                $.pop.tips(data.error);
                            } else {
                                $.pop.tips(data.error);
                                if (data.errType != null) {
                                    if (data.errType == "NOSESSION") {
                                        setTimeout(function () {
                                            window.location.href = data.errUrl;
                                            return false;
                                        }, 400);
                                    }
                                }
                            }
                        }, "json").error(function (XMLHttpRequest, textStatus, errorThrown) {
                            $.pop.load(false, null);
                            $.pop.tips("系统繁忙，请稍后" + XMLHttpRequest.status + "," + XMLHttpRequest.readyState + "," + textStatus);
                        });
                    }
                },
                rite:{
                    text:"再看看"
                },
                text:"确认要提交吗？"
            };
            $.pop.chio(opts);
        }
    }
}